﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Data.OracleClient;
using ReflectionStudio.Core.Events;
namespace WPFExcelReport
{
    class DSTREQYARNReport : BaseReport
    {
        #region ----------------PROPERTIES----------------------------------
        public OracleConnection OracleDB;
        public OracleCommand orlReadCommand = new OracleCommand();
        public IntexReptServBLClient proxy;
        private Dictionary<string, object> dicParamater;
        public DataSet dsResult;
        public DataSet setUI = new DataSet();
        string ABPAUFFKRS;
        string ABPAUFFLFD;
        string ABPAUFFPOS;
        string DocType;
        string CellName = "";
        string CellValue = "";
        string strCompany;
        string strExcelFile;
        #endregion
        public DSTREQYARNReport()
            : base()
        {
        }
        public DSTREQYARNReport(Dictionary<string, object> dicParamater)
            : base(dicParamater)
        {
            DocType = dicParamater["DocType"].ToString().Trim();
            strCompany = dicParamater["Company"].ToString().Trim();
            strExcelFile = dicParamater["ExcelFile"].ToString().Trim();
            #region Excel  columns
            
            #endregion           						
            
        }
        #region------------------------------Function------------------------

        public void FillInWARPYARN(DataSet setSoruce)
        {
            try
            {
                Int32 I = 4;
                Int32 J = 64;
                DataTable dtSoruce = setSoruce.Tables["WARPYARN"];
                foreach (DataRow dataRow in dtSoruce.Rows)
                {
                    /*ARTICLE,A.BAGGART,A.BAGGFARBE,A.BAGBEM,C.WAFGRPBEZ, REQ,COUNTS*/

                   exAgent.SetCellValue(2, 6, dataRow["ARTICLE"].ToString());
                   exAgent.SetCellValue(2, 19, dataRow["WAFGRPBEZ"].ToString());
                   exAgent.SetCellValue(I, 1, dataRow["BAGGFARBE"].ToString());
                   exAgent.SetCellValue(I + 1, 1, dataRow["BAGBEM"].ToString());
                   //exAgent.SetCellValue(I, 6, dataRow["COUNTS"].ToString());
                   exAgent.SetCellValue(I, 6, dataRow["BAGGART"].ToString());
                   exAgent.SetCellValue(I, 10, dataRow["REQ1"].ToString());

                   exAgent.ShowRows(I+1,1,I+1,26);

                   //exAgent.SetCellValue(J, 1, dataRow["BAGBEM"].ToString() + "(" + dataRow["COUNTS"].ToString() + ")");
                   exAgent.SetCellValue(J, 1, dataRow["BAGBEM"].ToString() + "(" + dataRow["BAGGART"].ToString() + ")");
                   exAgent.SetCellValue(J, 9, dataRow["REMARK"].ToString());
                   I = I + 2;
                   J = J + 1;
                }

            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
        }
        public void FillInWEFTYARN(DataSet setSoruce)
        {
            try
            {
                Int32 I = 4;
                DataTable dtSoruce = setSoruce.Tables["WEFTYARN"];
                foreach (DataRow dataRow in dtSoruce.Rows)
                {
                    /*ARTICLE,WAGGART,A.WAGGFARBE,A.WAGBEM,WAFMUDESS, REQ,COUNTS*/

                    exAgent.SetCellValue(2, 5, dataRow["ARTICLE"].ToString());
                    exAgent.SetCellValue(2, 15, dataRow["WAFMUDESS"].ToString());
                    exAgent.SetCellValue(I, 1, dataRow["WAGGFARBE"].ToString());
                    exAgent.SetCellValue(I + 1, 1, dataRow["WAGBEM"].ToString());
                    //exAgent.SetCellValue(I, 5, dataRow["COUNTS"].ToString());
                    exAgent.SetCellValue(I, 5, dataRow["WAGGART"].ToString());
                    exAgent.SetCellValue(I, 8, dataRow["REQ"].ToString());

                    exAgent.ShowRows(I + 1, 1, I + 1, 26);
                    I = I + 2;
                }

            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
        }
        public override void WriteExcelReport(string fileType)
        {
            string filename = "";
            string sheetName = "";
            string Standard = "DSTAB45";
            strExcelFile = @"DST\DSTInventory.xls";
            DataRow row = dsSource.Tables["WARPYARN"].Rows[0];
            string ARTICLE = row["ARTICLE"].ToString().Trim();
            string filePath = @"C:\intex.w\Report\" + strExcelFile;
            exAgent.Open(filePath);
            //exAgent.Company = strCompany;
            exAgent.strExcelFile = strExcelFile;
            string filedate = DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString();
            filename = @"经纱流转卡" + ARTICLE + ".xls";
            exAgent.CreateNewSheet(filename, Standard, filedate);
            FillInWARPYARN(dsSource);
            base.WriteExcelReport("DirectPrint");
        }
        public void WriteExcel(string fileType)
        {
            string filename = "";
            string sheetName = "";
            string Standard = "DSTAB55DI";
            strExcelFile = @"DST\DSTInventory.xls";
            DataRow row = dsSource.Tables["WEFTYARN"].Rows[0];
            string ARTICLE = row["ARTICLE"].ToString().Trim(); 
            string filePath = @"C:\intex.w\Report\" + strExcelFile;
            exAgent.Open(filePath);
            //exAgent.Company = strCompany;
            exAgent.strExcelFile = strExcelFile;
            string filedate = DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString();
            filename = @"纬纱流转卡" + ARTICLE + ".xls";
            exAgent.CreateNewSheet(filename, Standard, filedate);
            FillInWEFTYARN(dsSource);
            base.WriteExcelReport("DirectPrint");
        }
        #endregion
    }
}